<template>
  <div>
            <el-table
    :data="this.replyList"
    style="width: 100%">
    <el-table-column
      label="用户名"
      width="180"
      prop="cuser"
      >
     
    </el-table-column>
    <el-table-column
      label="内容"
      width="180"
      prop="cinfo"
      >
     
    </el-table-column>
    <el-table-column
      label="点赞数"
      width="180"
      prop="cstar"
      >
     
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <!-- <el-button
          size="mini"
           @click="like(scope.row.id)">点赞</el-button> -->
        <img src="../assets/zan.png" v-if="scope.row.state=='yes'" @click="dianzan(scope.row)">
        <img src="../assets/budianzzan.png" v-if="scope.row.state=='no'" @click="dianzan(scope.row)">
      </template>
    </el-table-column>
  </el-table>
  </div>
</template>

<script>
import ajax from "../service/ajax.js"
import { mapState } from 'vuex';
import {getUser,logout,refreshToken} from '../service/user'
export default {
     data() {
    return {
      replyList:[],
      user:{},
      token:'',
    }
  },
      methods: {
        async findAll(){
        // alert("进入方法  "+JSON.stringify(this.user));
             var info;
             if(this.user != null){
                 alert("登录了  "+JSON.stringify(this.user));
                info = await ajax.postToken("/project/comment/list",null,this.token)
             }else{
                 alert("用户没登录")
                 info = await ajax.getSubmit("/project/comment/smallList")
             }
           
            // alert("findAll 状态   "+info.status)
            if(info.status == "1"){
                this.replyList = info.data
                // alert(JSON.stringify("集合对象"+ JSON.stringify( this.replyList)));
                }
    
        },

    async dianzan(scope){
        
         var parm = {};
            parm.userId = this.user.userId;
            parm.cId=scope.id;
            if(scope.state == 'no'){
                parm.num=scope.cstar + 1;
            }else if(scope.state == 'yes'){
                parm.num=scope.cstar - 1;
            }

        var info  = await ajax.postToken("/project/comment/star",parm,this.token)
        alert(" 点赞的状态"+info.status);
        if(info.data == 'ok'){
            this.findAll();
        }
      },
      },
       
    
        async created(){
            alert("token的数据  "+this.$cookies.get('token'));
            this.token = this.$cookies.get('token');
            let response = await getUser(this.$cookies.get('token'));
             alert("response  "+JSON.stringify(response));
            this.user = response.data;
            this.findAll();
        },
        computed:{
      ...mapState('user',['token'])
    },
}
</script>

<style>

</style>